package com.edu.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.edu.common.utils.R;
import com.edu.eduservice.entity.EduCourse;
import com.edu.eduservice.entity.EduTeacher;
import com.edu.eduservice.service.EduCourseService;
import com.edu.eduservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/eduservice/bannerfront")
@CrossOrigin
@Api(description="查询前8条热门课程,查询前4条名师")
public class IndexController {

    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;


    //查询前8条热门课程,查询前4条名师
    @GetMapping("/index")
    public R index(){
         //查询前8条热门课程
   /*     QueryWrapper<EduCourse> wrapper =new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 8");
        List<EduCourse> eduList = courseService.list(wrapper);*/

        List<EduCourse> eduList = courseService.findHotCourse();

        //查询前4条名师
      /*  QueryWrapper<EduTeacher> teacherQueryWrapper = new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id");
        teacherQueryWrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherQueryWrapper);*/
        List<EduTeacher> teacherList = teacherService.findTeacher();
        return R.ok().data("eduList",eduList).data("teacher",teacherList);
    }



}
